package server;

import java.io.*;
import java.net.*;
import client.ClientThread;

public class ChatServer {
    
    static  Socket clientSocket = null;
    static  ServerSocket serverSocket = null;

    ClientThread[] ct = new ClientThread[10];           
    
    public ChatServer(int port)
    {
		// The default port
		int port_number=2222;
		
		if (port>0)
			System.out.println("Usage: java MultiThreadChatServer \n"+
					   "Now using port number="+port_number);
		else 
			port_number=port;
	
        try   {serverSocket = new ServerSocket(port_number);}
        catch (IOException e){System.out.println(e);}
		
		while(true)
		{
		    try 
		    {
		    	System.out.println("WARTE AUF CLIENT");
		    	clientSocket = serverSocket.accept();
		    	System.out.println("HABE CLIENT");
				for(int i=0; i<=9; i++)
		    	{
			    	if(ct[i]==null)
					{
				    	(ct[i] = new ClientThread(clientSocket, ct)).start();
				    	break;
					}
				}
		    }
		    catch (IOException e) {
			System.out.println(e);}
		}    	
    }
}
